Conditions | 9 |
Paths | 44 |
Total Lines | 92 |
Lines | 92 |
Ratio | 100 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
||
8 | function CoverImage(el, cb) { |
||
9 | _classCallCheck(this, CoverImage); |
||
10 | |||
11 | var _this = this; |
||
12 | |||
13 | _this.$el = el ? el : window; |
||
14 | _this.$img = _this.getElementForSizing(); |
||
15 | _this.disableOnMobile = _this.$el.dataset['cover-image-mobile'] === 'false'; |
||
16 | _this.cb = cb || function () { |
||
17 | //DEBUG console.log("Default callback"); |
||
18 | }; |
||
19 | |||
20 | _this.positioning = { |
||
21 | x: 0.5, |
||
22 | y: 0.5 |
||
23 | }; |
||
24 | _this.options = { |
||
25 | parallax: _this.$el.dataset.coverImageParallax === 'true' |
||
26 | }; |
||
27 | |||
28 | if (!_this.$img) { |
||
29 | console.log('Error:', 'no image found', _this.$img); |
||
30 | return; |
||
31 | } |
||
32 | |||
33 | _this.imageWidth = _this.$img.width; |
||
34 | _this.imageHeight = _this.$img.height; |
||
35 | |||
36 | // If the image doesn't have harcoded width|height |
||
37 | // attributes then load the image to calculate |
||
38 | // the dimensions |
||
39 | if (!_this.imageWidth || !_this.imageHeight) { |
||
40 | console.log('No dimensions found. Generating image:', _this.$img.attr('src')); |
||
41 | _this.img = new Image(); |
||
42 | _this.img.src = _this.$img.attr('src'); |
||
43 | |||
44 | _this.imageWidth = _this.img.width; |
||
45 | _this.imageHeight = _this.img.height; |
||
46 | } |
||
47 | |||
48 | if (_this.disableOnMobile && window.innerWidth < 480) { |
||
49 | return; |
||
50 | } |
||
51 | |||
52 | _this.elementDimensions = { |
||
53 | height: _this.$el.clientHeight, |
||
54 | width: _this.$el.clientWidth |
||
55 | }; |
||
56 | |||
57 | _this.$el.style = '\n\t\t\toverflow : hidden;\n\t\t\tposition : relative;\n\t\t'; |
||
58 | |||
59 | if (!_this.$img) { |
||
60 | // TODO: Implement load |
||
61 | setTimeout(function () { |
||
62 | new CoverImage(_this.$el); |
||
63 | }, 1000); |
||
64 | } else { |
||
65 | _this.resizeImage(); |
||
66 | } |
||
67 | |||
68 | _this.$img.addEventListener('load', function () { |
||
69 | _this.resizeImage(); |
||
70 | }, false); |
||
71 | |||
72 | _this.$el.addEventListener('transitionend', function () { |
||
73 | _this.resizeImage(); |
||
74 | }, false); |
||
75 | |||
76 | var erd = elementResizeDetectorMaker({ |
||
77 | strategy: 'scroll' |
||
78 | }); |
||
79 | |||
80 | erd.listenTo(_this.$el, function () { |
||
81 | _this.resizeImage(); |
||
82 | }); |
||
83 | |||
84 | _this.$el.addEventListener('animationend', function () { |
||
85 | _this.resizeImage(); |
||
86 | }, false); |
||
87 | |||
88 | window.addEventListener('resize', function () { |
||
89 | _this.resizeImage(); |
||
90 | }, true); |
||
91 | |||
92 | window.addEventListener('ci.resize', function () { |
||
93 | _this.resizeImage(); |
||
94 | }, true); |
||
95 | |||
96 | if (_this.options.parallax) { |
||
97 | _this.draw(); |
||
98 | } |
||
99 | } |
||
100 | |||
231 | //# sourceMappingURL=coverimage.js.map |